package com.vpen.iot.model.dto;

/**
 * 状态模式
 * @author Vpen
 * @date 2024/8/14 13:34
 */
public class AppContext {

    public static final UserState LOGIN_STATE = new LoginState();

    public static final UserState UNLOGIN_STATE = new UnLoginState();

    private UserState currentState = UNLOGIN_STATE;

    {
        UNLOGIN_STATE.setAppContext(this);
        LOGIN_STATE.setAppContext(this);
    }

    public void setState(UserState state) {
        this.currentState = state;
        this.currentState.setAppContext(this);
    }

    public UserState getState() {
        return this.currentState;
    }

    public void forward() {
        this.currentState.forward();
    }

    public void collect() {
        this.currentState.collect();
    }

    public void comment(String comment) {
        this.currentState.comment(comment);
    }

    public static void main(String[] args) {
        AppContext context = new AppContext();
        context.forward();
        context.collect();
        context.comment("说的太好了，双手双脚给个赞👍");
    }

}
